package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.dto.OrderDto;
import cn.jiahua.hospital.dto.UserDto;
import cn.jiahua.hospital.dto.YOrderDto;
import cn.jiahua.hospital.mapper.YOrderMapper;
import cn.jiahua.hospital.pojo.YOrder;
import cn.jiahua.hospital.service.YOrderService;
import lombok.val;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

import javax.annotation.Resource;

@Service
public class YOrderServiceImpl implements YOrderService {

    @Resource
    private YOrderMapper yOrderMapper;



    @Override
    public YOrder getYOrderById(Integer id) {
        return yOrderMapper.getYOrderById(id);
    }

    @Override
    public YOrderDto getYOrderById_hospital(Integer id, Integer hospitalId) {
        return yOrderMapper.getYOrderById_hospital(id, hospitalId);
    }

    @Override
    public List<YOrder> getYOrderListByMap(Map<String, Object> param) {
        return yOrderMapper.getYOrderListByMap(param);
    }

    @Override
    public List<YOrderDto> getYOrderListByMap_hospital(Map<String, Object> param) {
        return yOrderMapper.getYOrderListByMap_hospital(param);
    }

    @Override
    public Integer getYOrderCountByMap_hospital(Map<String, Object> param) {
        return yOrderMapper.getYOrderCountByMap_hospital(param);
    }

    @Override
    public Integer getYOrderCountByMap(Map<String, Object> param) {
        return yOrderMapper.getYOrderCountByMap(param);
    }

    @Override
    public Integer qdtxAddYOrder(YOrder yOrder) {
        yOrder.setCreatTime(new Date());
        return yOrderMapper.insertYOrder(yOrder);
    }

    @Override
    public Integer qdtxModifyYOrder(YOrder yOrder) {
        return yOrderMapper.updateYOrder(yOrder);
    }

    @Override
    public Integer qdtxDeleteYOrderById(Integer id) {
        return yOrderMapper.deleteYOrderById(id);
    }

    @Override
    public Integer qdtxBatchDeleteYOrder(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return yOrderMapper.batchDeleteYOrder(param);
    }

    @Override
    public Page<YOrder> queryYOrderPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = yOrderMapper.getYOrderCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<YOrder> yOrderList = yOrderMapper.getYOrderListByMap(param);
        page.setList(yOrderList);
        return page;
    }

    @Override
    public Page<YOrder> queryYOrderPageByMapOfUser(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = yOrderMapper.getYOrderCountByMapOfUser(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<YOrder> yOrderList = yOrderMapper.getYOrderListByMapOfUser(param);
        page.setList(yOrderList);
        return page;
    }

    @Override
    public List<YOrder> getYOrderListByMapOfUser(Map<String, Object> param) {
        return yOrderMapper.getYOrderListByMapOfUser(param);
    }

    @Override
    public Integer getYOrderCountByMapOfUser(Map<String, Object> param) {
        return yOrderMapper.getYOrderCountByMapOfUser(param);
    }

    @Override
    public YOrder getYOrderById_orderid(String orderid) {
        return yOrderMapper.getYOrderById_orderid(orderid);
    }

    @Override
    public OrderDto getOrderInfoByOrderId(String orderId) throws Exception {
        OrderDto orderDto = yOrderMapper.getOrderInfoByOrderId(orderId);
        return orderDto;
    }

    @Override
    public List<UserDto> getOrderByUserId(Integer userId) throws Exception {
        List<UserDto> userDtos = yOrderMapper.getOrderByUserId(userId);
        return userDtos;
    }


}